package com.atyuntuku.yuntuku.common;

import cn.hutool.core.util.ObjectUtil;
import com.atyuntuku.yuntuku.exception.ErrorCode;
import com.atyuntuku.yuntuku.exception.ThrowUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * ClassName: UserRoleEnum
 * Package: com.atyuntuku.yuntuku.common
 * Description:
 *
 * @Author qinglong wei
 * @Create 2025/10/5 11:01
 * @Version 1.0
 */
@AllArgsConstructor
@Getter
public enum UserRoleEnum {

    USER("普通用户", "user"),
    ADMIN("管理员", "admin");

    private String desc;
    private String role;

    public static UserRoleEnum getUserRole(String value) {
        ThrowUtils.throwIf(ObjectUtil.isEmpty(value), ErrorCode.PARAMS_ERROR, "用户role传递错误");
        for (UserRoleEnum t : UserRoleEnum.values()) {
            if (t.getRole().equals(value))
                return t;
        }
        return null;
    }

}
